﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using YKhoa_Lib.BLL;

namespace YKhoa_Controls
{
    public partial class ChiDinh : System.Web.UI.UserControl
    {
        Khoa Khoa = null;
        So_GoiKham SoGK = null;
        public string MaNV { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            Khoa = new Khoa();
            SoGK = new So_GoiKham();
            if(!IsPostBack)
            {
                Initialize();
            }
        }

        private void Initialize()
        {
            BindingDanhMucKhoa();
            BindingDanhSachDichVu();
            BindingGoiChiDinh();
            //dropDownChuyenKhoa.Attributes.Add("onchange","loadChiTietDichVuTrongNhom(this.value,'')");
        }

        private void BindingDanhMucKhoa()
        {
            List<Khoa> lst = Khoa.LoadDanhMucKhoa();
            //dropDownChuyenKhoa.DataSource = lst;
            //dropDownChuyenKhoa.DataTextField = "TenKhoa";
            //dropDownChuyenKhoa.DataValueField = "MaKhoa";
            //dropDownChuyenKhoa.DataBind();   
            string script = "";
            foreach(Khoa item in lst)
            {
                script += "<option value=\""+ item.MaKhoa +"\">"+ item.TenKhoa +"</option>";
            }
            Page.ClientScript.RegisterStartupScript(GetType(), "GenerateDropDownKhoa", "$('#YKCT-CD-dropDownChuyenKhoa').append('" + script + "');", true);
        }

        private void BindingDanhSachDichVu()
        {
            List<Khoa> lst = Khoa.PhanLoaiHienThi();                        
            lst.Add(new Khoa("", "+NHÓM CHỈ ĐỊNH", "1"));
            string script = "";
            Khoa itemKhoa = null;
            bool first = false;
            for (int i = 0; i < lst.Count; i++)
            {
                if (i == 0) continue;
                itemKhoa = lst[i];                
                if (itemKhoa.Loai == "1")
                {
                    if(!first)
                    {
                        script += "<h3>" + itemKhoa.TenKhoa + "</h3><div>";
                        first = true;
                    }
                    else
                    {
                        script += "</div><h3 >" + itemKhoa.TenKhoa + "</h3><div>";
                    }
                }
                else
                {
                    script += "<div id=\"divExpand_" + itemKhoa.MaKhoa + "\" style=\"position:relative; width:100px\"><a href=\"javascript:void(0);\" id=\"" + itemKhoa.MaKhoa + "\" class=\"khoa-item item-nhom-pl\" >" + itemKhoa.TenKhoa + "</a></div><br />";                                        
                }
            }
            script += "</div>";
            Page.ClientScript.RegisterStartupScript(GetType(), "ScriptGenerate", "$('#acorditionPhanLoaiKhoa').append('" + script + "');", true);
            
        }

        private void BindingGoiChiDinh()
        {
            if(!string.IsNullOrEmpty(MaNV))
            {
                SoGK.MaNV = MaNV;
                List<So_GoiKham> lst = SoGK.LayDanhSachSoGoiKham();
                string script = "";
                foreach (So_GoiKham item in lst)
                {
                    script += "<option value=\"" + item.MaGK + "\">" + item.TenGoiKham + "</option>";
                }
                Page.ClientScript.RegisterStartupScript(GetType(), "ScriptGenerateSoGK", "$('#YKCT-CD-dropDownGoiChiDinh').append('" + script + "');", true);
            }            
        }
    }
}